package com.yjq.pojo;

/**
 * @author 尹嘉琪
 * @create 2021-12-09 21:08
 */
public class Rectangle extends Shape {

    private double width; // 矩形的宽

    private double height; // 矩形的高

    private String shape;

    public Rectangle() {
    }

    public Rectangle(double width, double height) {
        this.width = width;
        this.height = height;
    }

    public String getShape() {
        return shape;
    }

    public void setShape(String shape) {
        this.shape = shape;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    /**
     * 计算面积
     * @return
     */
    @Override
    Double calAre() {
        return width * height;
    }

    /**
     * 计算周长
     * @return
     */
    @Override
    Double calPer() {
        return (width + height) * 2;
    }

    /**
     * 输出矩形相关信息
     * @return
     */
    @Override
    public String printMessage() {
        String s = "";
        if (width == height) {
            s += "当前为正方形";
            shape = "正方形";
        } else {
            s += "当前为长方形";
            shape = "长方形";
        }
        return s + "，面积为：" + calAre() + ", 周长为：" + calPer();
    }

    /**
     * 判断图形是否合法
     * @return
     */
    public boolean isRectangle() {
        if (width <= 0 || height <= 0) {
            return false;
        } else {
            return true;
        }
    }
}
